/************************************************************************
 *
 * stdio.h
 *
 * (c) Copyright 1996-2005 Analog Devices, Inc.  All rights reserved.
 * $Revision: 1.2 $
 ************************************************************************/

#pragma once
#ifndef __NO_BUILTIN
#pragma system_header /* stdio.h */
#endif

#ifndef __STDIO_DEFINED
#define __STDIO_DEFINED

#include <yvals.h>

#ifndef NULL
#ifdef __cplusplus
#define NULL    0
#else
#define NULL    ((void *)0)
#endif
#endif

#define BUFSIZ          256
#define EOF             (-1)
#define FILENAME_MAX    32
#define FOPEN_MAX       10
#define L_tmpnam        32
#define TMP_MAX         25

/* C Standard names for setvbuf arg */
#define _IOFBF          0
#define _IOLBF          1
#define _IONBF          2

#define SEEK_SET        0
#define SEEK_CUR        1
#define SEEK_END        2

#ifdef __cplusplus
typedef _Fpost fpos_t;
#else
typedef unsigned long fpos_t;
#endif

#if !defined(_SIZE_T) && !defined(_SIZET) && !defined(__SIZE_T_DEFINED)
  #define __SIZE_T_DEFINED
  #define _SIZE_T
  #define _SIZET
  typedef _Sizet size_t;
#endif

/* Analog extensions to stdio.h are located in
 * a platform specific include file.
 * Use the compile option -D__NO_ANSI_EXTENSIONS__
 * to exclude any such extensions.
 */
#if !defined( __NO_ANSI_EXTENSIONS__ )
#if defined ( __ADSPTS__ )

#include <stdio_ts.h>

#endif    /* __ADSPTS__             */
#endif    /* __NO_ANSI_EXTENSIONS__ */


#ifdef __TS_BYTE_ADDRESS

typedef struct {
    unsigned int    _Mode;
    int             fileID;
    unsigned char*  _Next;       /* always considered valid     */
    unsigned char*  _Rend;       /* always considered valid     */
    unsigned char*  _Wend;       /* always considered valid     */
/* even more private: */
    unsigned char*  bufadr;
    unsigned char*  _Buf;
    unsigned char*  _Bend;
    unsigned char*  rsave;
    unsigned char   onechar;    /* temporary buffer on a word boundary */
    int             nback;
    unsigned char   _Back[2];
}
	FILE;

#else

typedef struct {
    unsigned int    _Mode;
    int             fileID;
    unsigned long   _Next;       /* always considered valid     */
    unsigned long   _Rend;       /* always considered valid     */
    unsigned long   _Wend;       /* always considered valid     */
/* even more private: */
    unsigned char*  bufadr;
    unsigned long   _Buf;
    unsigned char*  _Bend;
    unsigned long   rsave;
    unsigned char   _Back[2];
    unsigned char   onechar;    /* temporary buffer */
    int             nback;
}
	FILE;
#endif

#define _FILET

#ifdef __cplusplus
extern "C" {
#endif

extern FILE*    _Files[FOPEN_MAX];
#define stdin   _Files[0]
#define stdout  _Files[1]
#define stderr  _Files[2]

#ifdef __TS_BYTE_ADDRESS
#define clearerr clearerr_ba
#define fclose   fclose_ba
#define feof     feof_ba
#define ferror   ferror_ba
#define fflush   fflush_ba
#define fgetc    fgetc_ba
#define fgets    fgets_ba
#define fgetpos  fgetpos_ba
#define fopen    fopen_ba
#define fputc    fputc_ba
#define fputs    fputs_ba
#define fread    fread_ba
#define freopen  freopen_ba
#define fseek    fseek_ba
#define fsetpos  fsetpos_ba
#define ftell    ftell_ba
#define fwrite   fwrite_ba
#define getchar  getchar_ba
#define gets     gets_ba
#define putchar  putchar_ba
#define puts     puts_ba
#define remove   remove_ba
#define rename   rename_ba
#define rewind   rewind_ba
#define setbuf   setbuf_ba
#define setvbuf  setvbuf_ba
#define ungetc   ungetc_ba

#ifdef __DOUBLES_ARE_FLOATS__
  #define perror   perror_ba
  #define printf   _printf32_ba
  #define sprintf  _sprintf32_ba
  #define fprintf  _fprintf32_ba
  #define fscanf   _fscanf32_ba
  #define scanf    _scanf32_ba
  #define sscanf   _sscanf32_ba
  #define vfprintf _vfprintf32_ba
  #define vprintf  _vprintf32_ba
  #define vsprintf _vsprintf32_ba
#else
  #define perror   _perror64_ba
  #define printf   _printf64_ba
  #define sprintf  _sprintf64_ba
  #define fprintf  _fprintf64_ba
  #define fscanf   _fscanf64_ba
  #define scanf    _scanf64_ba
  #define sscanf   _sscanf64_ba
  #define vfprintf _vfprintf64_ba
  #define vprintf  _vprintf64_ba
  #define vsprintf _vsprintf64_ba
#endif /* __DOUBLES_ARE_FLOATS__ */

#else

#ifdef __DOUBLES_ARE_FLOATS__
  #define printf   _printf32
  #define sprintf  _sprintf32
  #define fprintf  _fprintf32
  #define fscanf   _fscanf32
  #define scanf    _scanf32
  #define sscanf   _sscanf32
  #define vfprintf _vfprintf32
  #define vprintf  _vprintf32
  #define vsprintf _vsprintf32
#else
  #define perror   _perror64
  #define printf   _printf64
  #define sprintf  _sprintf64
  #define fprintf  _fprintf64
  #define fscanf   _fscanf64
  #define scanf    _scanf64
  #define sscanf   _sscanf64
  #define vfprintf _vfprintf64
  #define vprintf  _vprintf64
  #define vsprintf _vsprintf64
#endif /* __DOUBLES_ARE_FLOATS__ */

#endif /* __TS_BYTE_ADDRESS */

void clearerr(FILE*);
int fclose(FILE*);
int feof(FILE*);
int ferror(FILE*);
int fflush(FILE*);
int fgetc(FILE*);
int fgetpos(FILE*, fpos_t*);
char* fgets(char*, int, FILE*);
FILE* fopen(const char*, const char* _mods);
int fprintf(FILE* _stream, const char* _fmt, ...);
int fputc(int, FILE*);
int fputs(const char*, FILE*);
size_t fread(void* _buf, size_t _sz, size_t _nElem, FILE*);
FILE* freopen(const char*, const char* _mods, FILE*);
int fscanf(FILE*, const char* _fmt, ...);
int fseek(FILE*, long _off, int _smode);
int fsetpos(FILE*, const fpos_t*);
long ftell(FILE*);
size_t fwrite(const void* _buf, size_t _sz, size_t _nElem, FILE*);
int getc(FILE*);
int getchar(void);
char* gets(char*);
void perror(const char*);
int printf(const char* _fmt, ...);
int putc(int, FILE*);
int putchar(int);
int puts(const char*);
int remove(const char*);
int rename(const char* _oldname, const char* _newname);
void rewind(FILE*);
int scanf(const char* _fmt, ...);
void setbuf(FILE*, char*);
int setvbuf(FILE*, char*, int, size_t);
int sprintf(char* _buf, const char* _fmt, ...);
int sscanf(const char* _buf, const char* _fmt, ...);
int ungetc(int, FILE*);
int vfprintf(FILE*, const char*, char*);
int vprintf(const char*, char*);
int vsprintf(char*, const char*, char*);

#if 0  /* stdio functions not supported */
  FILE* tmpfile(void);
  char* tmpnam(char*);
#endif



#ifdef __cplusplus
}
#endif

#ifdef __TS_BYTE_ADDRESS
#define getc(str)                                            \
      ((str)->_Next < (str)->_Rend ? *(((str)->_Next)++)     \
                                   : (getc)(str))

#define putc(c,str)                                          \
      ((str)->_Next < (str)->_Wend ? *(((str)->_Next)++) = c \
                                   : (putc)((c),(str)))
#endif

#endif /* __STDIO_DEFINED */
